package com.scu.hotelsystem.controller;

import com.github.pagehelper.PageInfo;
import com.scu.hotelsystem.pojo.GoodsOrder;
import com.scu.hotelsystem.service.GoodsOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
public class GoodsOrderController {
    @Autowired
    private GoodsOrderService goodsOrderService;

    //分页
    @RequestMapping("/goodsOrder.findAll")
    public ModelAndView findAll(@RequestParam(name = "page", required = true, defaultValue =
            "1") int page, @RequestParam(name = "size", required = true, defaultValue = "10")
                                        int size) throws Exception {
        List<GoodsOrder> ordersList = goodsOrderService.findAll(page, size);
        ModelAndView mv = new ModelAndView();
        PageInfo pageInfo=new PageInfo(ordersList);
        mv.setViewName("goodsorder-list");
        mv.addObject("pageInfo", ordersList);
        return mv;
    }

    @RequestMapping("/goodsOrder.findById")
    public ModelAndView findById(@RequestParam(name = "id", required = true) Integer ordersId) throws Exception {
        ModelAndView mv = new ModelAndView();
        GoodsOrder orders = goodsOrderService.findById(ordersId);
        mv.addObject("orders",orders);
        mv.setViewName("goodsorder-show");
        return mv;
    }
}
